
package com.jsfcompref.model;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import webservices.InstanciaServicio;
import java.util.List;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class CarritoBacking {
   
    private UIData instancias;

    public UIData getInstancias() {
        return instancias;
    }

    public void setInstancias(UIData instancias) {
        this.instancias = instancias;
    }
    
    public String borrarInstancia() {
   
      InstanciaServicio inst = (InstanciaServicio) getInstancias().getRowData();
        
      FacesContext context = FacesContext.getCurrentInstance();
      ELContext elContext = context.getELContext();
      Application application = context.getApplication();
            
      ExpressionFactory expressionFactory = application.getExpressionFactory();
      ValueExpression ve = expressionFactory.createValueExpression(elContext, "#{uBean}",UBean.class);
      
      UBean ubean = (UBean) ve.getValue(elContext);
       
      ubean.getCliente().getFacturas().get(0).getLineas().remove(inst);
        
    return "carrito";
    }
    
}
